const fs = require('fs');
const path = require('path');

console.log('=== Sourcemap 调试信息 ===');

// 检查构建目录
const buildDir = path.join(process.cwd(), 'dist/build/mp-weixin');
console.log('构建目录:', buildDir);

if (fs.existsSync(buildDir)) {
  console.log('✅ 构建目录存在');
  
  // 列出所有文件
  const files = fs.readdirSync(buildDir, { recursive: true });
  const jsFiles = files.filter(file => file.endsWith('.js'));
  const mapFiles = files.filter(file => file.endsWith('.map'));
  
  console.log('\n📁 JS文件数量:', jsFiles.length);
  console.log('📁 Sourcemap文件数量:', mapFiles.length);
  
  // 检查主要的sourcemap文件
  const mainMapPath = path.join(buildDir, 'appservice/common/main.js.map');
  if (fs.existsSync(mainMapPath)) {
    console.log('\n✅ main.js.map 存在');
    const mapContent = fs.readFileSync(mainMapPath, 'utf8');
    const mapData = JSON.parse(mapContent);
    console.log('Sourcemap版本:', mapData.version);
    console.log('Sourcemap源文件数量:', mapData.sources ? mapData.sources.length : 'N/A');
    console.log('Sourcemap源文件示例:', mapData.sources ? mapData.sources.slice(0, 3) : 'N/A');
  } else {
    console.log('\n❌ main.js.map 不存在');
  }
  
  // 检查app.js
  const appJsPath = path.join(buildDir, 'appservice/app.js');
  if (fs.existsSync(appJsPath)) {
    console.log('\n✅ app.js 存在');
    const appContent = fs.readFileSync(appJsPath, 'utf8');
    if (appContent.includes('sourceMappingURL')) {
      console.log('✅ app.js 包含 sourceMappingURL');
    } else {
      console.log('❌ app.js 不包含 sourceMappingURL');
    }
  }
  
} else {
  console.log('❌ 构建目录不存在');
}

console.log('\n=== 当前配置 ===');
console.log('Release版本: sida-repair-fe@0.30.0');
console.log('URL前缀: ~/appservice/');
console.log('Strip前缀: webpack://_n_e/');
